package com.tanhua.server.controller;

import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /**
     * 首页-今日佳人
     *   业务：根据touserId查询推荐用户，查询score最高的为用户即可
     *   接口路径：GET  /todayBest
     *   返回值：
     *      ResponseEntity<TodayBest>
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        //根据touserId查询推荐用户，查询score最高的为用户即可
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 查询推荐列表
     *  GET  /recommendation
     *  Query参数
     *     page，pagesize
     *  返回值
     *      PageResult  -- items列表中存放的都是TodayBest
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10")  Integer pagesize) {
        PageResult vo = tanhuaService.recommendation(page,pagesize);
        return ResponseEntity.ok(vo);
    }

    /**
     * 佳人信息：
     *   接口路径：GET   {userId}/personalInfo
     *   返回值：
     *      TodayBest
     */
    @GetMapping("/{userId}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("userId") Long userId) {
        TodayBest vo = tanhuaService.personalInfo(userId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 查看用户的陌生人问题
     * 接口路径：GET    /strangerQuestions?userId=10
     * 请求参数：Query   userId
     * 返回值：陌生人问题（String）
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
       String txt =  tanhuaService.strangerQuestions(userId);
       return ResponseEntity.ok(txt);
    }


    /**
     * 回复陌生人问题（发送好友申请）
     * 接口路径：POST       /strangerQuestions
     * 请求参数：Body：
     *      userId（对方的用户id），reply（回复内容）
     * 返回值：null
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity reply(@RequestBody Map map) {
        //1、获取参数
        String reply = map.get("reply").toString();
        String temp = map.get("userId").toString();
        Long userId = Long.valueOf(temp);
        //2、调用service
        tanhuaService.reply(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 搜索附近
     * 接口路径：GET  /search
     * 请求参数：Query
     *  gender   distance
     * 返回值
     *  List<NearUserVo>
     */
    @GetMapping("/search")
    public ResponseEntity search(String gender,String distance) {
        List<NearUserVo> vos =  tanhuaService.search(gender,distance);
        return ResponseEntity.ok(vos);
    }
}
